<template>
  <div id="superUser_order">
    <el-main>
      <el-table :data="order">
        <el-table-column prop="orderNumber" label="订单号" width="190"></el-table-column>
        <el-table-column prop="name" label="昵称" width="70"></el-table-column>
        <el-table-column prop="entryTime" width="200" label="入库时间">
        </el-table-column>
        <el-table-column prop="outTime" label="出库时间" width="200">
          <template slot-scope="scope">
            <span v-if="+scope.row.outTime == ''">
                   <span slot="reference">未出库</span>
            </span>
            <span v-else-if="+scope.row.outTime !=''">{{ scope.row.outTime }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="parkingSpaceNumber" label="车位" width="120">
        </el-table-column>
        <el-table-column prop="licensePlateNumber" label="车牌号" width="100">
        </el-table-column>
        <el-table-column prop="orderPrice" label="订单金额" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.orderPrice }}元</span>
          </template>
        </el-table-column>
        <el-table-column prop="orderState" label="支付状态" width="100">
          <template slot-scope="scope">
              <span  v-if="+scope.row.orderState === 0" slot="reference">未支付</span>
            <span v-else-if="+scope.row.orderState === 1">已支付</span>
          </template>
        </el-table-column>
        <el-table-column prop="id" label="操作" width="200">
          <template slot-scope="scope">
            <el-popconfirm
                confirm-button-text='好的'
                cancel-button-text='不用了'
                icon="el-icon-info"
                icon-color="red"
                title="确定要删除这个订单吗？"
                @confirm="deleteOrder(scope.row.id)">
              <el-button slot="reference">删除</el-button>
            </el-popconfirm>
            <el-button @click="updateOrder(scope.row.id,scope.row.name,scope.row.parkingSpaceNumber,scope.row.licensePlateNumber,scope.row.orderPrice,scope.row.orderState)"
                slot="reference">修改
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
  </div>
</template>

<script>
export default {
  name: "superUser_order",
  props: {
    order: {
      type: Array,
      default: () => []
    },
    email: null,
  },
  methods: {
    updateOrder(id,name,parkingSpaceNumber,licensePlateNumber,orderPrice,orderState){
      this.$router.push({
        name: 'superUser_updateOrder',
        query: {
          id:id,
          name:name,
          parkingSpaceNumber:parkingSpaceNumber,
          licensePlateNumber:licensePlateNumber,
          orderPrice:orderPrice,
          orderState:orderState,
        }
      })
    },
    deleteOrder(id){
    this.$http.get("http://localhost:8088/superUser/deleteOrder",{
      params:{
        id:id,
      }
    }).then(resp=> {
      console.log(resp.data)
          this.$http.get("http://localhost:8088/superUser/findAllOrder").then(resp => {
            this.order = resp.data
            this.$router.push({
              name: 'superUser_order',
              query: {
                order: this.order,
              }
            }).catch(err => {
              console.log(err)
            })
          })
        }
    )
    }
  }
}
</script>

<style scoped>
#superUser_order {
  width: 100%;

}

</style>
